﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LightSwitch;
namespace LightSwitchApplication
{
    public partial class Visit
    {
        //partial void VisitType_Changed()
        //{
        //    //If the VisitType changes make sure to clear the VisitGoal selection
        //    if (this.VisitGoal != null)
        //    {
        //        if (this.VisitGoal.VisitType != this.VisitType)
        //            this.VisitGoal = null;
        //    }
        //}
        partial void VisitTimeFrom_Changed()
        {
            if (this.VisitTimeFrom > DateTime.MinValue && (this.VisitTimeTo == DateTime.MinValue || this.VisitTimeTo < this.VisitTimeFrom || this.VisitTimeTo == null))
                this.VisitTimeTo = this.VisitTimeFrom.AddHours(1);
        }

        partial void VisitCurrentState_Compute(ref string result)
        {
            if (this.DocumentStatusSet != null && this.DocumentStatusSet.Count() > 0)
            {
                result = this.DocumentStatusSet.OrderBy(sos => sos.StatusDate).Last().DocumentState.Name;
            }
        }

        partial void VisitTypeName_Compute(ref string result)
        {
            if (this.VisitGoal != null && this.VisitGoal.VisitType != null) result = this.VisitGoal.VisitType.VisitTypeName;
        }

    }
}
